

import 'package:flutter/material.dart';
import 'package:flutterdemo01/Demo55/Page5.dart';


main(){
  runApp(Demo55App());
}

class Demo55App extends StatefulWidget {
  const Demo55App({Key? key}) : super(key: key);

  @override
  _Demo55AppState createState() => _Demo55AppState();
}

class _Demo55AppState extends State<Demo55App> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(

      //routes: routes,
      onGenerateRoute: onGenerateRoute,
      theme: ThemeData(primaryColor: Colors.lightBlue),
      home: Scaffold(
        body: App5(),
      ),
    );
  }
}

class App5 extends StatefulWidget {
  const App5({Key? key}) : super(key: key);

  @override
  _App5State createState() => _App5State();
}

class _App5State extends State<App5> {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        SizedBox(height: 300,),
        ElevatedButton(onPressed: (){

          Navigator.popAndPushNamed(context, '/list', arguments: {'msg':'this is transfer message'});

        }, child: Text('传值按钮'))
      ],

    );
  }
}

final routes = {
  '/list':(context, {arguments})=> Page5(arguments: arguments),
};


//固定写法
var onGenerateRoute = (RouteSettings settings) {
 // print('object');
    String? name = settings.name;
  final Function pageContentBuilder = routes[name] as Function;
  if (pageContentBuilder != null) {
    if (settings.arguments != null) {
      final Route route = MaterialPageRoute(
          builder: (context) =>
              pageContentBuilder(context, arguments: settings.arguments));
      return route;
    } else {
      final Route route =
      MaterialPageRoute(builder: (context) => pageContentBuilder(context));
      return route;
    }
  }
};
